//
// Created by YxMin on 2024/7/4.
//
#ifndef GAME_BUTTON_H
#define GAME_BUTTON_H

#include <cstdio>
#include "Element.h"
#include "UI.h"

class Button:public Element {
private:
    char text[32];
    bool multiLine = false;
    COLORREF fontColor;
public:
    Button(int uid, int x1, int y1, int x2, int y2,int radius = 0, int (*callback)(void *) = nullptr, char* text = nullptr,COLORREF fontColor = BLACK,bool multiLine = false)
           : Element(uid, x1, y1, x2,y2,radius, callback) {
        //init(uid,x1,y1,x2,y2,callback)
        //RegisterElement(this);
        this->fontColor = fontColor;
        this->multiLine = multiLine;
        strcpy(this->text ,text);
    }
    ~Button() override = default;
    void showText() {
        //showText(text);
        drawtext(text,&area,DT_CENTER|DT_VCENTER|(multiLine ? 0 : DT_SINGLELINE));
    }
    void draw() override {
        if(radius > 0) {
            roundrect(area.left,area.top,area.right,area.bottom,radius,radius);
        } else {
            rectangle(area.left,area.top,area.right,area.bottom);
        }
        settextcolor(fontColor);
        showText();
        settextcolor(BLACK);
    }
    char* getText() {
        return text;
    }
};
#endif //GAME_BUTTON_H
